package com.bjsxt.controller;

import com.bjsxt.domain.Sms;
import com.bjsxt.model.Result;
import com.bjsxt.service.SmsService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ALIENWARE
 * @version v1.0.0
 * @package : com.bjsxt.controller
 * @description :
 * Alibaba SMS 短信服务的控制层
 * @create on : 12/27/2023
 **/
@RestController
@RequestMapping("/sms")
@Api(tags = "短信中心控制器")
public class SmsController {

    /**
     * SMS 短信服务业务层接口
     */
    @Autowired
    private SmsService smsService;

    /**
     * 发送一条短信
     *
     * @param sms 短信信息对象
     * @return 统一响应对象
     */
    @PostMapping("/sendTo")
    // @PreAuthorize("hasAuthority('user_query')")
    @ApiOperation(value = "发送一条短信", authorizations = {@Authorization("Authorization")})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sms", value = "Sms 对象的 json 数据", dataType = "String", paramType = "body", example = "{}")
    })
    public Result<Void> sendMessage(@Validated @RequestBody Sms sms) {
        // 调用业务层方法进行短信的发送
        boolean flag = smsService.sendSms(sms);
        // 如果为 true 更新成功
        if (flag) return Result.success("发送成功");
        // 如果为 false 更新失败
        return Result.fail("发送失败");
    }
}
